<?php
    require_once("./classes/sessao.php");
    require_once("./classes/interfaces.php");
    require_once("./classes/conexao.php");

    session_start();

    if (isset($_SESSION['ANAWEB']))
    {
        if (!empty($_POST['permitir']) && $_POST['permitir'] == "Sim" && !empty($_POST['idusuario']) && !empty($_POST['idbib']))
        {
            $conexao = new Conexao();
            $conexao->Conecta();
            $bibid = (int)$_POST['idbib'];
            $usrid = (int)$_POST['idusuario'];
            $sql1 = $conexao->Executa("INSERT INTO colaborador_biblioteca (id_bib, id_user) VALUES ({$bibid},{$usrid})");
            $sql2 = $conexao->Executa("DELETE FROM requisicoes_bib WHERE id_bib = $bibid AND id_user = $usrid");
            if ($sql1 && $sql2)
                header("Location: gerenciarbiblioteca.php");
            else
            {
            }
        }
        elseif (!empty($_POST['permitir']) && $_POST['permitir'] == "Nao" && !empty($_POST['idusuario']) && !empty($_POST['idbib']))
        {
            $conexao = new Conexao();
            $conexao->Conecta();
            $bibid = (int)$_POST['idbib'];
            $usrid = (int)$_POST['idusuario'];
            $sql = $conexao->Executa("DELETE FROM requisicoes_bib WHERE id_bib = $bibid AND id_user = $usrid");
            if ($sql)
                header("Location: gerenciarbiblioteca.php");
            else
            {
            }
        }
    }
?>